package com.example.controller;

import com.example.common.Result;
import com.example.service.TagService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import com.example.entity.Tag;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/tag")
public class TagController {
    @Resource
    private TagService tagService;

    @PostMapping("/add")
    public Result add(@RequestBody Tag tag){
        tagService.save(tag);
        return Result.success("新增标签成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        tagService.deleteById(id);
        return Result.success("删除标签成功");
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        tagService.deleteBatch(ids);
        return Result.success("删除标签成功");
    }
    @PutMapping("/update")
    public Result updateById(@RequestBody Tag tag) {
        tagService.updateById(tag);
        return Result.success("更新标签信息成功");
    }
    @GetMapping("/selectAll")
    public Result selectAll(Tag tag) {
        List<Tag> list = tagService.selectAll(tag);
        return Result.success("查询标签信息列表成功",list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(Tag tag,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Tag> page = tagService.selectPage(tag, pageNum, pageSize);
        return Result.success("分页查询标签信息列表成功",page);
    }
}
